/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.osbosoftware.vista.utils;

import java.util.Iterator;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

/**
 *
 * @author osboCEO
 */
public class UtilidadesControlador {


    public void addMensaje(FacesMessage.Severity sev,String summary) {
        String mensajedeco=summary;
        FacesMessage facesMessage = new FacesMessage(sev,mensajedeco,null);
        FacesContext context = FacesContext.getCurrentInstance();
        UIComponent compo = findComponent(context.getViewRoot(), "temple");
        FacesContext.getCurrentInstance().addMessage(compo.getClientId(context), facesMessage);
    }
    public void addMensajeInfo(String mensaje){
        addMensaje(FacesMessage.SEVERITY_INFO,mensaje);
    }
    public void addMensajeError(String mensaje){
        addMensaje(FacesMessage.SEVERITY_ERROR,mensaje);
    }

    private UIComponent findComponent(UIComponent parent, String id) {
        if (id.equals(parent.getId())) {
            return parent;
        }
        Iterator<UIComponent> kids = parent.getFacetsAndChildren();
        while (kids.hasNext()) {
            UIComponent kid = kids.next();
            UIComponent found = findComponent(kid, id);
            if (found != null) {
                return found;
            }
        }
        return null;
    }
}
